package com.surelution.projects.crm

class GasDensity {

    static constraints = {
		type(unique:['time'])
    }
	
	GasType type
	Date time
	Float density
	
	/**
	 * 取出同time最接近的密度
	 * @param type
	 * @param time
	 * @return
	 */
	public static GasDensity getDensity(GasType type, Date time) {
		def d = GasDensity.createCriteria().list() {
			eq("type", type)
		}
		if(d) {
			def m = time.time
			return d.min{
				abs(m - it.time.time)
			}
		}
		return null
	}
}
